package com.huike.web.controller.report;

import com.huike.clues.domain.vo.ClueReportVo;
import com.huike.common.core.controller.BaseController;
import com.huike.common.core.domain.AjaxResult;
import com.huike.common.core.page.TableDataInfo;
import com.huike.contract.domain.TbContract;
import com.huike.report.domain.DTO.ContractpageDTO;
import com.huike.report.domain.DTO.TbActivityDTO;
import com.huike.report.domain.DTO.TbCluePageDTO;
import com.huike.report.domain.vo.ActivityStatisticsVo;
import com.huike.report.domain.vo.LineChartVo;
import com.huike.report.domain.vo.VulnerabilityMapVo;
import com.huike.report.services.SysReportservices;
import com.huike.web.result.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.util.List;
import java.util.Map;

/**
 * @Description TODO
 * @Author 小不夜侯
 * @Date 2023-08-29 9:04
 */
@RestController
@RequestMapping("/report")
@Slf4j
@Api(tags = "统计分析相关接口")
public class SysReportController extends BaseController {
    @Resource
    private SysReportservices sysReportservices;

    /**
     * 客户统计明细列表
     *
     * @param contractpageDTO
     * @return
     */


    @GetMapping("/contractStatisticsList")
    @ApiOperation("客户统计明细列表")
    public TableDataInfo page1(ContractpageDTO contractpageDTO) {
        log.info("客户统计明细列表:{}", contractpageDTO);
        startPage();
        List<TbContract> list = sysReportservices.selectpage1(contractpageDTO);
        return getDataTable(list);
    }

    /**
     * 统计新增客户
     *
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     */
    @GetMapping("/contractStatistics/{beginCreateTime}/{endCreateTime}")
    public LineChartVo countupdataClient(@PathVariable() @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate beginCreateTime,
                                         @PathVariable() @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endCreateTime) {
        log.info("统计新增客户:{},{}", beginCreateTime, endCreateTime);
        LineChartVo lineChartVo = sysReportservices.countupdataClient(beginCreateTime, endCreateTime);
        return lineChartVo;
    }

    /**
     * 客户统计学科分布统计报表
     *
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     */
    @GetMapping("/subjectStatistics/{beginCreateTime}/{endCreateTime}")
    public AjaxResult<List<ReportSubjectStatisticsData>> subjectStatistics(@PathVariable() @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate beginCreateTime,
                                                                           @PathVariable() @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endCreateTime
    ) {
        return AjaxResult.success(sysReportservices.subjectStatistics(beginCreateTime, endCreateTime));
    }

    /**
     * 销售统计归属人报表
     *
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     */
    @GetMapping("/ownerShipStatisticsList/{beginCreateTime}/{endCreateTime}")
    public TableDataInfo<ReportSalesOwnerShipStatisticsListData> ownerShipStatisticsList(@PathVariable() @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate beginCreateTime,
                                                                                         @PathVariable() @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endCreateTime,
                                                                                         Integer pageNum, Integer pageSize
    ) {
        log.info("销售统计归属人报表:{},{},{},{}", beginCreateTime, endCreateTime, pageNum, pageSize);
        startPage();
        List<Map<String, Object>> ros = sysReportservices.ownerShipStatisticsList(beginCreateTime, endCreateTime);
        return getDataTable(ros);
    }

    /**
     * 销售统计归属渠道明细列表
     *
     * @param beginCreateTime
     * @param endCreateTime
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/channelStatisticsList/{beginCreateTime}/{endCreateTime}")
    public TableDataInfo<ReportSalesChannelStatisticsListData> channelStatisticsList(@PathVariable() @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate beginCreateTime,
                                                                                     @PathVariable() @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endCreateTime,
                                                                                     Integer pageNum, Integer pageSize
    ) {
        log.info("销售统计归属人报表:{},{},{},{}", beginCreateTime, endCreateTime, pageNum, pageSize);
        startPage();
        List<Map<String, Object>> ros = sysReportservices.channelStatisticsList(beginCreateTime, endCreateTime);
        return getDataTable(ros);
    }

    /**
     * 销售统计归属部门明细列表
     *
     * @param beginCreateTime
     * @param endCreateTime
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/deptStatisticsList/{beginCreateTime}/{endCreateTime}")
    public TableDataInfo<ReportSalesDeptStatisticsListData> deptStatisticsList(@PathVariable() @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate beginCreateTime,
                                                                               @PathVariable() @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endCreateTime,
                                                                               Integer pageNum, Integer pageSize
    ) {
        log.info("销售统计归属人报表:{},{},{},{}", beginCreateTime, endCreateTime, pageNum, pageSize);
        startPage();
        List<Map<String, Object>> maps = sysReportservices.deptStatisticsList(beginCreateTime, endCreateTime);

        return getDataTable(maps);
    }

    /**
     * 销售统计报表
     *
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     */
    @GetMapping("/salesStatistics/{beginCreateTime}/{endCreateTime}")
    public LineChartVo salesStatistics(@PathVariable() @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate beginCreateTime,
                                       @PathVariable() @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endCreateTime) {
        log.info("统计新增客户:{},{}", beginCreateTime, endCreateTime);
        LineChartVo lineChartVo = sysReportservices.salesStatistics(beginCreateTime, endCreateTime);
        return lineChartVo;
    }

    /**
     * 线索统计明细列表
     *
     * @param tbCluePageDTO
     * @return
     */
    @GetMapping("/cluesStatisticsList")
    @ApiOperation("客户统计明细列表")
    public TableDataInfo cluesStatisticsList(TbCluePageDTO tbCluePageDTO) {
        log.info("客户统计明细列表:{}", tbCluePageDTO);
        startPage();
        List<ClueReportVo> list = sysReportservices.cluesStatisticsList(tbCluePageDTO);
        return getDataTable(list);
    }

    /**
     * 线索统计新增线索数量报表
     *
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     */
    @GetMapping("/cluesStatistics/{beginCreateTime}/{endCreateTime}")
    public LineChartVo cluesStatistics(@PathVariable() @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate beginCreateTime,
                                       @PathVariable() @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endCreateTime) {
        log.info("统计新增客户:{},{}", beginCreateTime, endCreateTime);
        LineChartVo lineChartVo = sysReportservices.cluesStatistics(beginCreateTime, endCreateTime);
        return lineChartVo;
    }

    /**
     * 客户统计学科分布统计报表
     *
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     */
    @GetMapping("/getVulnerabilityMap/{beginCreateTime}/{endCreateTime}")
    public AjaxResult<VulnerabilityMapVo> getVulnerabilityMap(@PathVariable() @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate beginCreateTime,
                                                              @PathVariable() @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endCreateTime
    ) {
        return AjaxResult.success(sysReportservices.getVulnerabilityMap(beginCreateTime, endCreateTime));
    }


    /**
     * 渠道统计活动明细列表
     *
     * @param tbActivityDTO
     * @return
     */
    @GetMapping("/activityStatisticsList")
    @ApiOperation("客户统计明细列表")
    public TableDataInfo activityStatisticsList(TbActivityDTO tbActivityDTO) {
        log.info("客户统计明细列表:{}", tbActivityDTO);
        startPage();
        List<ActivityStatisticsVo> list = sysReportservices.activityStatisticsList(tbActivityDTO);
        return getDataTable(list);
    }
    /**
     * 渠道统计
     *
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     */
    @GetMapping("/chanelStatistics/{beginCreateTime}/{endCreateTime}")
    public AjaxResult< List<ReportChannelStatisticsData> > chanelStatistics(@PathVariable() @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate beginCreateTime,
                                       @PathVariable() @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endCreateTime) {
        log.info("统计新增客户:{},{}", beginCreateTime, endCreateTime);

        return AjaxResult.success( sysReportservices.chanelStatistics(beginCreateTime, endCreateTime));
    }
    /**
     *渠道统计-活动统计
     *
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     */
    @GetMapping("/activityStatistics/{beginCreateTime}/{endCreateTime}")
    public AjaxResult< List<ReportActivityStatisticsData> > activityStatistics(@PathVariable() @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate beginCreateTime,
                                                                          @PathVariable() @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endCreateTime) {
        log.info("统计新增客户:{},{}", beginCreateTime, endCreateTime);

        return AjaxResult.success( sysReportservices.activityStatistics(beginCreateTime, endCreateTime));
    }
}